package com.mmall.demo2.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

/**
 * shiro密码校验规则，用于对比“输入密码”及“数据库密码”
 */
public class CredentialMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken authToken, AuthenticationInfo info) {
        // 获取用户登陆填写信息
        UsernamePasswordToken token = (UsernamePasswordToken) authToken;

        // 获取登陆密码 && 正确密码
        String password = new String(token.getPassword());
        String dbPassword = (String) info.getCredentials();

        // 判断密码是否相等
        return this.equals(password, dbPassword);
    }
}
